{% extends 'base.html' %}
{% load i18n staticfiles tz stats %}
{% block title %}{% trans 'Squad Rankings' %} / {{ block.super }}{% endblock title %}

{% block head %}
{% endblock head %}

{% block content %}
    <section id="content">
        <div class="wrapper">
            <div class="content_head">
                <div class="content_title">
                    {% trans 'Squad Rankings' %}
                    <div class="content_title_sm" id="sort_by_text"></div>
                </div>
                <div class="form_search">
                    <form action="" method="GET">
                        <input type="hidden" name="tour" value="{{ request.tour.id }}"/>
                        <input type="text" name="search" value="" placeholder="{% trans 'Search squad' %}">
                    </form>
                </div>
            </div>

            {% if squads %}
            <div class="content_table">
                <div class="head_row">
                    <div class="cell" style="width: 60px;"></div>
                    <div class="cell"></div>
                    <div class="cell" style="width: 60px;"></div>
                    <div class="cell" style="width: 90px;">
                        <a class="sort_by" href="?sort_by=-num_members">
                            <img src="{% static 'img/icons/small/players.png' %}" width="18" height="18" alt="" title="">
                        </a>
                    </div>
                    <div class="cell" style="width: 90px;">
                        <a class="sort_by" href="?sort_by=-ak_total">
                            <img src="{% static 'img/icons/small/ak.png' %}" width="18" height="18"
                                 alt="{% trans 'Air Kills' %}" title="{% trans 'Air Kills' %}">
                        </a>
                    </div>
                    <div class="cell" style="width: 90px;">
                        <a class="sort_by" href="?sort_by=-gk_total">
                            <img src="{% static 'img/icons/small/gk.png' %}" width="18" height="18"
                                 alt="{% trans 'Ground Kills' %}" title="{% trans 'Ground Kills' %}">
                        </a>
                    </div>
                    <div class="cell" style="width: 90px;">
                        <a class="sort_by" href="?sort_by=-flight_time">
                            <img src="{% static 'img/icons/small/ft.png' %}" width="18" height="18"
                                 alt="{% trans 'Flight Time (hours:minutes)' %}" title="{% trans 'Flight Time (hours:minutes)' %}">
                        </a>
                    </div>
                    <div class="cell" style="width: 90px;">
                        <a class="sort_by" href="?sort_by=-kd">
                            <img src="{% static 'img/icons/small/kd.png' %}" width="18" height="18"
                                 alt="K/D" title="K/D">
                        </a>
                    </div>
                    <div class="cell" style="width: 90px;">
                        <a class="sort_by" href="?sort_by=-khr">
                            <img src="{% static 'img/icons/small/khr.png' %}" width="18" height="18"
                                 alt="K/Hr" title="K/Hr">
                        </a>
                    </div>
                    <div class="cell" style="width: 90px;">
                        <a class="sort_by" href="?sort_by=-rating">
                            <img src="{% static 'img/icons/small/rating.png' %}" width="18" height="18"
                                 alt="{% trans 'Rating' %}" title="{% trans 'Rating' %}">
                        </a>
                    </div>
                </div>
                {% for squad in squads %}
                <a class="row" href="{{ squad.get_profile_url }}">
                    <div class="cell">{{ squads.start_index|add:forloop.counter0 }}</div>
                    <div class="cell" style="text-align: left;">{{ squad.name|truncatechars:32 }}</div>
                    <div class="cell img">
                        {% include 'inline/table_coal_pref_icon.html' with coal_pref=squad.coal_pref %}
                    </div>
                    <div class="cell">{{ squad.num_members }}</div>
                    <div class="cell">{{ squad.ak_total }}</div>
                    <div class="cell">{{ squad.gk_total }}</div>
                    <div class="cell">{{ squad.flight_time|seconds_to_time }}</div>
                    <div class="cell">{{ squad.kd }}</div>
                    <div class="cell">{{ squad.khr }}</div>
                    <div class="cell" title="{{ squad.rating }}">{{ squad.rating_format }}</div>
                </a>
                {% endfor %}
            </div>
                {% if squads.paginator.num_pages > 1 %}
                    <div class="paginator3000" id="paginator"></div>
                {% endif %}
            {% endif %}

            <div class="info" style="padding-top: 20px;">
                <div>
                </div>
            </div>
        </div>
    </section>
{% endblock content %}

{% block bottom %}
    {{ block.super }}
    <script src="{% static 'js/table.js' %}"></script>
    <script>
        var sort_by_text = {
            'ak_total': '{% trans 'on the number of air kills' %}',
            'gk_total': '{% trans 'on the number of ground kills' %}',
            'flight_time': '{% trans 'on the flight time (hours:minutes)' %}',
            'kd': '{% trans 'on the average number of kill per one death (K/D)' %}',
            'khr': '{% trans 'on the average number of kill per one hour (K/Hr)' %}',
            'rating': '',
            'num_members': '{% trans 'on the number of squad members' %}'
        };

        $(document).ready(function() {
            uri_sort_by('-rating', sort_by_text);
            var paginator = new Paginator('paginator', {{ squads.paginator.num_pages }}, 15, {{ squads.number }}, uri_paginator);
        });
    </script>
{% endblock bottom %}
